<%--
    Document   : detailpromotionday
    Created on : Nov 20, 2011, 3:16:57 PM
    Author     : Venus
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.*, java.text.*,Beans.ThamSoHT,Models.ThamSoHT_Model, Models.MonAn_Model, Models.TienTe_Model, Models.KhuyenMai_Model"%>
<%
            int langid = (Integer) session.getAttribute("langid"); // ngôn ngữ hiện tại
            String dsts = " 'price', 'discount', 'delete', 'saleprice', 'dayinweek', 'notice', 'foodname', 'rightmsg' ";
            ThamSoHT[] mdsts = ThamSoHT_Model.DSThamSo(dsts, langid); // mảng chứa các tham số của trang này.

            String dayinweek = mdsts[0].getTenTS();
            String delete = mdsts[1].getTenTS();
            String discount = mdsts[2].getTenTS();
            String foodname = mdsts[3].getTenTS();
            String notice = mdsts[4].getTenTS();
            String price = mdsts[5].getTenTS();
            String rightmsg = mdsts[6].getTenTS();
            String saleprice = mdsts[7].getTenTS();

            String msgright = notice + "/" + rightmsg;
            Vector vDSKMTN = (Vector) request.getAttribute("DSKMTN");
            String makm = (String) request.getAttribute("makm");

            int numpage = 0;// khởi tạo số trang = 0
            int vsize = vDSKMTN.size();
            if (vsize % 8 == 0) // mỗi trang có 6 dòng
            {
                numpage = vsize / 8;
            } else {
                numpage = vsize / 8 + 1;
            }
            String xx = (String) request.getAttribute("item");
            int item = Integer.parseInt(xx);
            String tenma = (String) request.getAttribute("tenma");
            String ngaythu = (String) request.getAttribute("ngaythu");
            String gia = (String) request.getAttribute("gia");
            String giamgia = (String) request.getAttribute("giamgia");
            NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
%>
<script type="text/javascript">
    function keypress(e){
        //Hàm dùng để ngăn người dùng nhập các ký tự khác ký tự số vào TextBox
        var keypressed = null;
        if (window.event)
        {
            keypressed = window.event.keyCode; //IE
        }
        else
        {
            keypressed = e.which; //NON-IE, Standard
        }
        if (keypressed < 48 || keypressed > 57 )
        { //CharCode của 0 là 48 (Theo bảng mã ASCII)
            //CharCode của 9 là 57 (Theo bảng mã ASCII)
            if (keypressed == 8 || keypressed == 127  || keypressed == 44 || keypressed == 46  )
            {//Phím Delete và Phím Back
                return;
            }
            return false;
        }
    }
</script>
<table class="mytable" border="0" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th style=" width: 25%;">
                <a href="#" id="titledskv1" style="margin-top: 5px;" class="down" lang="<%=msgright%>" shape="<%=makm %>"   name="1" onclick="SortSearchTenMAKM(this.className, this.name, this.lang, this.shape)">
                    <div style="float:left"><%=foodname %></div>
                    <div id="sortkv1" style=" margin-right: 25px;" class="down1"></div>
                </a>
            </th>
            <th style="width: 17%;">
                <a href="#" id="titledskv2" style="margin-top: 5px;" class="down" lang="<%=msgright%>" shape="<%=makm %>"  name="1" onclick="SortSearchNgayKM(this.className, this.name, this.lang, this.shape)">
                    <div style="float:left"><%=dayinweek%></div>
                    <div id="sortkv2" style=" margin-right: 20px;" class="down1"></div>
                </a>
            </th>
            <th style="width: 18%;">
                <a href="#" id="titledskv3" style="margin-top: 5px;" class="down" lang="<%=msgright%>" shape="<%=makm %>"  name="1" onclick="SortSearchGiaKM(this.className, this.name, this.lang, this.shape)">
                    <div style="float:left"><%=price%> (<%=TienTe_Model.LayKyHieuTT(langid)%>)</div>
                    <div id="sortkv3" style=" margin-right: 20px;" class="down1"></div>
                </a>
            </th>
            <th style="width: 14%;">
                <%=discount %>
            </th>
            <th style="width: 19%;">
                <%=saleprice%> (<%=TienTe_Model.LayKyHieuTT(langid)%>)
            </th>
            <th><center><%=delete%></center></th>
        </tr>
        <tr id="searchaddpro">
            <th><input type="textbox"  style=" width: 110px;"  value="<%=tenma%>" class="tenma text" ></th>
            <th><input type="textbox"  style=" width: 70px;"  value="<%=ngaythu%>" class="ngaythu text" ></th>
            <th><input type="textbox"  style=" width: 60px;"  value="<%=gia%>" class="gia text"  onkeypress="return keypress(event)"></th>
            <th><input type="textbox"  style=" width: 35px;"  value="<%=giamgia%>" class="giamgia text"  maxlength="2" onkeypress="return keypress(event)"> %</th>
            <th></th>
            <th><img style=" margin-top: 2px; margin-left: 3px; margin-bottom: -7px; cursor: pointer;" name="<%=makm %>"  alt="1" src="../images/search1.png" lang="<%=msgright%>" onclick="SearchAddPro(this.alt, this.lang, this.name)"></th>
        </tr>
    </thead>
    <tbody>
        <%
            for (int i = (item - 1) * 8; i < (item - 1) * 8 + 8 && i < vsize; i++){
                Beans.KMTheoNgay kmtn = (Beans.KMTheoNgay) vDSKMTN.elementAt(i);%>
                <tr>
                    <td><%=MonAn_Model.LayTenMA(kmtn.getMaMA(), langid) %></td>
                    <td><%=KhuyenMai_Model.LayTenNgay(kmtn.getMaNgay(), langid)  %></td>
                    <td style="padding-right: 5px;"><div style=" width: 50px; text-align: right;"><%=nf.format(MonAn_Model.LayGia(kmtn.getMaMA())) %></div></td>
                    <td>
                        <div style=" float: left; width: 55px;"><input type="textbox" onkeypress="return keypress(event)" class="text" maxlength="2" style=" width: 35px;" value="<%=kmtn.getGiamGia() %>" alt="<%=kmtn.getMaKMTN() %>" name="<%=kmtn.getMaKM() %>" id="<%=msgright%>" onchange="UpdateGiamGia(this.alt, this.value, this.name, this.id)">  %</div>
                        <img style=" cursor: pointer; height: 18px; padding-right: 0; margin-left: 6px; margin-top: 2px;" alt="" src="../images/addmoney.png">
                    </td>
                    <td><div style=" width: 70px; text-align: right;"><%=nf.format(MonAn_Model.LayRsGia(kmtn.getMaMA(), kmtn.getGiamGia())) %></div></td>
                    <td><center><a href="#" id="<%=kmtn.getMaKMTN() %>" lang="<%=kmtn.getMaKM() %>" name="<%=msgright%>" onclick="DeleteProDay(this.id, this.name, this.lang)"><img style=" height: 18px; width: 18px;" alt="" src="../images/del.png"></a></center></td>
                </tr>
        <%  }%>
    </tbody>
</table>
<div class="pagination">
    <%
        int trang = 1;
        if (item > 1) {
            trang = item - 1;
        }
    %>
    <%
        if (vsize > 8) {%>
        <a href="#" class="prev"  name="<%= trang%>" lang="<%=msgright%>" id="<%=makm %>" onclick="SearchAddPro(this.name, this.lang, this.id)">«</a>
    <%      for (int c = 1; c <= numpage; c++) {
                if (c != item) {
    %>              <a href="#"  name="<%= c%>" lang="<%=msgright%>" id="<%=makm %>" onclick="SearchAddPro(this.name, this.lang, this.id)" ><%= c%></a>
    <%          } else {%><a class="current"> <%= c%></a> <% }
            }
    %>
    <%      if (item + 1 <= numpage) {
                trang = item + 1;
            } else {
                trang = item;
            }
    %>
            <a href="#" class="next"  name="<%= trang%>" lang="<%=msgright%>" id="<%=makm %>" onclick="SearchAddPro(this.name, this.lang, this.id)">»</a>
    <%  }
    %>
</div>